package com.haois.ws.web.module;

import com.haois.component.security.HandleToken;
import com.haois.ws.common.constant.Reply;
import com.haois.ws.common.util.RespUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * Created by RuiHaoZ on 2017/11/20.
 */
@RestController
public class BaseController {

    private Logger logger = LoggerFactory.getLogger(BaseController.class);


    @Value("${defined.image-upload_url}")
    public String imgDirFilePath;


    public HandleToken handleToken = new HandleToken();

    @RequestMapping(value = "/api", method = RequestMethod.GET)
    public String getApi() {
        List<Reply> replies = Reply.getApiMsg();
        Reply<List<Reply>> reply = new Reply<List<Reply>>("00", "upstream", replies);
        return reply.toJson();
    }

    @RequestMapping(value = "/json")
    public String index1(HttpServletResponse response, String json) {
        logger.info(json);
        RespUtil.setACAO(response);
        return json;
    }

    @RequestMapping(value = "/json/{json}")
    public String index2(HttpServletResponse response,@PathVariable String json) {
        logger.info(json);
        RespUtil.setACAO(response);
        return json;

    }
}
